<div class="navbar navbar-default" id="navbar">
    <script type="text/javascript">
        try {
            ace.settings.check('navbar', 'fixed')
        } catch (e) {
        }
    </script>

    <div class="navbar-container" id="navbar-container">
        <div class="navbar-header pull-left">
            <a href="/admin/index.html" class="navbar-brand">
                <small>
                    <i class="icon-leaf"></i>
                    发财猫后台管理系统
                </small>
            </a>
        </div>

        <div class="navbar-header pull-right" role="navigation">
            <ul class="nav ace-nav">
                <li class="light-blue dropdown-modal">
                    <a data-toggle="dropdown" href="#" class="dropdown-toggle" aria-expanded="false">
                        <img class="nav-user-photo" src="assets/images/tx.jpg">
                        <span class="user-info">
                        <small>Welcome,</small>
                        <span id="user_name_top">Jason</span>
                    </span>
                        <i class="icon-caret-down"></i>
                    </a>
                    <ul class="user-menu dropdown-menu-right dropdown-menu dropdown-yellow dropdown-caret dropdown-close">
                        <li>
                            <a href="javascript:void(0)" data-toggle="modal" data-target="#managerUserInfoModal">
                                <i class="icon-user"></i>
                                个人设置
                            </a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a href="javascript:void(0)" onclick="showLogOutConfirm()">
                                <i class="icon-power-off"></i>
                                退出登录
                            </a>
                        </li>
                    </ul>
                </li>
            </ul>
            <!--<a href="javascript:void(0)" onclick="showLogOutConfirm()" class="navbar-brand" id="user_name_top">-->

            <!--</a>-->
        </div>
    </div>
</div>
<div class="modal fade" id="managerUserInfoModal" tabindex="-1" role="dialog" aria-labelledby="managerUserInfoModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">个人信息</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" role="form" id="userInfoForm">
                    <input type="hidden" id="userid">
                    <div class="form-group">
                        <label for="username" class="col-sm-2 control-label">登录名</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="username" placeholder="请输入用户名">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="realname" class="col-sm-2 control-label">真实姓名</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="realname" placeholder="请输入真实姓名">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="phone" class="col-sm-2 control-label">手机号码</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="phone" placeholder="请输入手机号码">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="password" class="col-sm-2 control-label">登录密码</label>
                        <div class="col-sm-9">
                            <input type="password" class="form-control" id="password">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="editManagerUserInfo()">提交更改</button>
            </div>
        </div>
    </div>
</div>
<script>

    function logOut() {
        loadGetServer('/manager/login/logOut', {}, function (data) {
            if (data.code == 0) {
                window.location.href = "/admin/login.html";
            }
        });
    }

    function showLogOutConfirm(userid) {
        var r = confirm("确认退出登录？");
        if (r == true) {
            logOut(userid)
        }
    }

    function showLoginUserInfo() {
        loadGetServer("/manager/system/getLoginUserInfo", {}, function (data) {
            $("#user_name_top").html(data.realname);
        })
    }

    $('#managerUserInfoModal').on('show.bs.modal', function () {
        $("#userInfoForm")[0].reset();
        loadGetServer('/manager/system/getManagerUserInfo', {}, function (data) {
            if(data.code === 0){
                $("#userid").val(data.userInfo.id);
                $("#username").val(data.userInfo.username);
                $("#realname").val(data.userInfo.realname);
                $("#phone").val(data.userInfo.phone);
            } else {
                alert(data.msg);
            }
        });
    })

    function editManagerUserInfo(){
        var para = {
            userid: $("#userid").val(),
            username: $("#username").val(),
            realname: $("#realname").val(),
            phone: $("#phone").val(),
            password: $("#password").val()
        };
        loadGetServer('/manager/system/editManagerUserInfo', para, function (data) {
            if(data.code != 0){
                alert(data.msg);
            }else{
                alert('操作成功')
                $('#managerUserInfoModal').modal('hide');
            }
            loadData();
        });
    }

    showLoginUserInfo();

</script>